import { createStore, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage"; // defaults to localStorage for web

import rootReducer from "./reducer";

const persistConfig = {
  key: "root",
  storage,
  blacklist: ["user"], // 用户信息不在这里做持久化。
};

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const persistedReducer = persistReducer(persistConfig, rootReducer);

// export default () => {
//     let store = createStore(persistedReducer, composeEnhancers(applyMiddleware(thunk)));
//     let persistor = persistStore(store);
//     return {store, persistor}
// }

export const store = createStore(
  persistedReducer,
  composeEnhancers(applyMiddleware(thunk))
);
export const persistor = persistStore(store);
